const Tools = {
  alert: () => {
    alert(1)
  },
  isNull: (o) => {
    for (const i in o) {
      if (o[i] === '' || o[i] === undefined) {
        return true
      }
    }
    return false
  },
  isUdf: (str) => {
    if (str === undefined) {
      return ''
    }
    return str
  },
  toNull: (o) => {
    for (const i in o) {
      o[i] = ''
    }
  },
  firstUpperCase: (str) => {
    // return str.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase())
    return str.substring(0, 1).toLocaleUpperCase() + str.substring(1)
  },
  getPropValue: (name, prop, needPropValue, arr) => {
    for (let i = 0; i < arr.length; i++) {
      if (arr[i][prop] === name) {
        return arr[i][needPropValue]
      }
    }
  },
  /**
   * 解决数组，对象 引用1问题
   * @obj   要复制对象
   */
  getNewObj: (obj) => {
    const temp = {}
    for (const i in obj) {
      temp[i] = obj[i]
    }
    return temp
  },
  getName: (arr, value) => {
    for (let i = 0; i < arr.length; i++) {
      if (arr[i].value === value) {
        return arr[i].name
      }
    }
    return ''
  },
  getValue: (arr, name) => {
    for (let i = 0; i <= arr.length; i++) {
      if (arr[i].name === name) {
        return arr[i].value
      }
    }
    return ''
  },
  /**
   *    // let temp = ''
   // temp = this.layer_data.toString()
   // this.data = JSON.parse(temp)
   //
   // const deepClone = (obj) => ({
      //   __proto__: Object.getPrototypeOf(obj),
      //   ...obj
      // })
   // this.data = deepClone(this.layer_data)
   //
   // const deepClone = (obj) => {
      //   var proto = Object.getPrototypeOf(obj)
      //   return Object.assign({}, Object.create(proto), obj)
      // }
   // this.data = deepClone(this.layer_data)
   // cloneObj
   //  对象深拷贝
   * @param obj
   * @returns {Array}
   */
  cloneObj: (obj) => {
    if (obj instanceof Array) {
      const arr = []
      let arrTemp = ''
      for (let i = 0; i < obj.length; i++) {
        if (obj[i] instanceof Array || obj[i] instanceof Object) {
          arrTemp = Tools.cloneObj(obj[i])
          arr.push(arrTemp)
        } else {
          arrTemp = obj[i]
          arr.push(arrTemp)
        }
      }
      return arr
    } else if (obj instanceof Object) {
      const temp = {}
      for (const k in obj) {
        if (obj[k] instanceof Array || obj[k] instanceof Object) {
          temp[k] = Tools.cloneObj(obj[k])
        } else {
          temp[k] = obj[k]
        }
      }
      return temp
    }
  },
  /**
   *  在创建订单时，将对象属性取出来，换成属性值
   */
  getAttribute: (arr) => {
    const tempArr = Tools.cloneObj(arr)
    if (tempArr.length === 0) {
      return tempArr
    } else {
      for (let i = 0; i <= tempArr.length; i++) {
        for (const key in arr[i]) {
          if (tempArr[i][key] instanceof Object) {
            tempArr[i][key] = tempArr[i][key].value
          }
        }
      }
      return tempArr
    }
  }
}
export default Tools
